package cn.xenosp.server.web.controller;

import cn.xenosp.server.common.Result;
import cn.xenosp.server.common.annotation.LogInfo;
import cn.xenosp.server.common.tools.ObjectConvert;
import cn.xenosp.server.module.activiti.entity.DeploymentVO;
import cn.xenosp.server.module.activiti.service.DeploymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 项目名： service-web
 * 包路径： cn.xenosp.server.web.controller
 * 作者：   TongHui
 * 创建时间: 2025-03-12 17:24
 * 描述: TODO
 * 版本: 1.0
 */
@RestController
@RequestMapping("${app.config.api-base-url}/activiti/deploy")
public class DeploymentController {

    @Autowired
    private DeploymentService deploymentService;

    @LogInfo(operationModuleType = "部署管理",operationName = "查询列表",operationContent = "查询列表")
    @PostMapping("/getPage")
    public Result<?> save(@RequestBody String body){
        try {
            DeploymentVO deploymentVO = ObjectConvert.urlStringToClass(body,DeploymentVO.class);
            return Result.OK("成功",deploymentService.getByPaged(deploymentVO));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.error("失败",null);
    }

    @LogInfo(operationModuleType = "部署管理",operationName = "上传部署流程文件",operationContent = "上传部署流程文件")
    @PostMapping("/upload")
    public Result<?> upload(@RequestPart(value = "files") MultipartFile[] files){
        try {
            return Result.OK("成功",deploymentService.upload(files));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.error("失败",null);
    }

    @LogInfo(operationModuleType = "部署管理",operationName = "删除",operationContent = "删除")
    @PostMapping("/del")
    public Result<?> del(@RequestBody DeploymentVO deploymentVO){
        try {
            return Result.OK("成功",deploymentService.removeById(deploymentVO.getId()));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.error("失败",null);
    }
}
